Public Class frmCrear_UnidadLogica
    Private mstrValor As String
    Private SEPARADOR As Char
    Private Title As Boolean
    Public ReadOnly Property Valor() As String
        Get
            Valor = mstrValor
        End Get
    End Property
    Private Sub frmCrear_UnidadLogica_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        lblNombre.BackColor = Color.White
        lblAncho.BackColor = Color.White
        lblTipo.BackColor = Color.White
        lblTitulo.BackColor = Color.White
        lblAlto.BackColor = Color.White
        lblPesoVacio.BackColor = Color.White
        lblLargo.BackColor = Color.White

        lblNombre.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        lblTipo.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        lblTitulo.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        lblAncho.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        lblLargo.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        lblAlto.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        lblPesoVacio.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)

        txtNombre.BackColor = Color.White
        lstTipo.BackColor = Color.White
        txtAncho.BackColor = Color.White
        txtAlto.BackColor = Color.White
        txtLargo.BackColor = Color.White
        txtPeso.BackColor = Color.White

        txtNombre.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        lstTipo.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        txtAncho.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        txtAlto.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        txtLargo.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)
        txtPeso.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64)

        panelSuperior.Style.BackColor1.Color = Color.White
        panelSuperior.Style.BackColor1.Color = Color.White
        panelSuperior.Style.BorderColor.Color = Color.LightGray

        panelInferior.Style.BackColor1.Color = Color.White
        panelInferior.Style.BackColor2.Color = Color.Silver
        panelInferior.Style.BorderColor.Color = Color.LightGray

        txtNombre.Clear()
        lstTipo.Text = ""
        txtAncho.Clear()
        txtAlto.Clear()
        txtPeso.Clear()
        txtLargo.Clear()

        SEPARADOR = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator

        Line3.BackColor = Color.White
        Line3.ForeColor = System.Drawing.Color.FromArgb(224, 224, 224)

        If PARAMETROS.ENTRADA_dATOS = 1 Then
            txtNombre.CharacterCasing = CharacterCasing.Upper
        ElseIf PARAMETROS.ENTRADA_dATOS = 2 Then
            txtNombre.CharacterCasing = CharacterCasing.Lower

        ElseIf PARAMETROS.ENTRADA_dATOS = 3 Then
            'FORMAT_CULTURA
        ElseIf PARAMETROS.ENTRADA_dATOS = 0 Then
            txtNombre.CharacterCasing = CharacterCasing.Normal
        End If

        txtNombre.Focus()

    End Sub

    Private Sub txtNombre_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtNombre.KeyDown
        If e.KeyCode = Keys.Enter Then
            lstTipo.Focus()

        ElseIf e.KeyCode = Keys.Tab Then
            lstTipo.Focus()
        End If
    End Sub

    Private Sub txtNombre_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtNombre.TextChanged

    End Sub

    Private Sub lstTipo_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles lstTipo.KeyDown
        If e.KeyCode = Keys.Enter Then
            txtAncho.Focus()
        ElseIf e.KeyCode = Keys.Tab Then
            txtAncho.Focus()
        End If
    End Sub

    Private Sub lstTipo_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles lstTipo.SelectedIndexChanged

    End Sub

    Private Sub txtAncho_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtAncho.KeyDown
        If e.KeyCode = Keys.Enter Then
            txtAlto.Focus()
        ElseIf e.KeyCode = Keys.Tab Then
            txtAlto.Focus()
        ElseIf e.KeyCode = 13 Then
            Aplica_Config_Numeros(txtAncho, SEPARADOR)
        End If
    End Sub

    Private Sub txtAncho_Leave(sender As Object, e As System.EventArgs) Handles txtAncho.Leave
        Formatea_Numeros(txtAncho, 2)
    End Sub

    Private Sub txtAncho_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtAncho.TextChanged
        Valida_Formato_Numeros(txtAncho, SEPARADOR)
    End Sub

    Private Sub txtAlto_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtAlto.KeyDown
        If e.KeyCode = Keys.Enter Then
            txtLargo.Focus()
        ElseIf e.KeyCode = Keys.Tab Then
            txtLargo.Focus()
        ElseIf e.KeyCode = 13 Then
            Aplica_Config_Numeros(txtAlto, SEPARADOR)
        End If
    End Sub

    Private Sub txtAlto_Leave(sender As Object, e As System.EventArgs) Handles txtAlto.Leave
        Formatea_Numeros(txtAlto, 2)
    End Sub

    Private Sub txtAlto_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtAlto.TextChanged
        Valida_Formato_Numeros(txtAlto, SEPARADOR)
    End Sub

    Private Sub txtLargo_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtLargo.KeyDown
        If e.KeyCode = Keys.Enter Then
            txtPeso.Focus()
        ElseIf e.KeyCode = Keys.Tab Then
            txtPeso.Focus()
        ElseIf e.KeyCode = 13 Then
            Aplica_Config_Numeros(txtLargo, SEPARADOR)
        End If
    End Sub

    Private Sub txtLargo_Leave(sender As Object, e As System.EventArgs) Handles txtLargo.Leave
        Formatea_Numeros(txtLargo, 2)
    End Sub

    Private Sub txtLargo_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtLargo.TextChanged
        Valida_Formato_Numeros(txtLargo, SEPARADOR)
    End Sub

    Private Sub txtPeso_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtPeso.KeyDown
        If e.KeyCode = Keys.Enter Then
            Guardar()
        ElseIf e.KeyCode = Keys.Tab Then
            Guardar()
        ElseIf e.KeyCode = 13 Then
            Aplica_Config_Numeros(txtPeso, SEPARADOR)
        End If
    End Sub

    Private Sub txtPeso_Leave(sender As Object, e As System.EventArgs) Handles txtPeso.Leave
        Formatea_Numeros(txtPeso, 2)
    End Sub

    Private Sub txtPeso_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtPeso.TextChanged
        Valida_Formato_Numeros(txtPeso, SEPARADOR)
    End Sub
   
    Sub Guardar()
        If Len(txtNombre.Text) Then
            MsgBox("Debes indicar el nombre para la unidad de logistica", MsgBoxStyle.Exclamation, "Aviso")
            txtNombre.Focus()
            Exit Sub
        End If

        If Len(lstTipo.Text.Trim) Then
            MsgBox("Debes indicar el tipo para la unidad de logistica", MsgBoxStyle.Exclamation, "Aviso")
            lstTipo.Focus()
            Exit Sub
        End If

        Dim tipo As Integer
       

        Dim UNIDADES As New clsUNIDADES_MEDIDA
        Dim RESULTADO As Integer = UNIDADES.UNIDADES_LOGISTICA(txtNombre.Text, TIPO_PALLET_UNIDAD(lstTipo.Text), txtLargo.Text, txtAlto.Text, txtAncho.Text, txtPeso.Text)
        If RESULTADO = 0 Then
            MsgBox("La unidad indicada ya existe", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        ElseIf RESULTADO = -1 Then
            MsgBox("No se pudo validar la unidad de logistica", MsgBoxStyle.Exclamation, "Aviso")
            Me.DialogResult = Windows.Forms.DialogResult.Cancel
            Close()
        Else
            mstrValor = txtNombre.Text
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Close()

        End If
    End Sub

    Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Close()
    End Sub

    Private Sub btnTodosRegresar_Click(sender As System.Object, e As System.EventArgs) Handles btnTodosRegresar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Close()
    End Sub
End Class